package cn.com.simple.learning.webflux.service;

import cn.com.simple.learning.core.entity.User;
import cn.com.simple.learning.webflux.mapper.UserMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * @author Jianxing.Jia
 * @date 2022/1/28
 * @description 批量添加
 */
@Service
public class UserService extends ServiceImpl<UserMapper, User> {

    @Transactional(rollbackFor = Exception.class)
    public Integer batchSave(List<User> users) {
        if (CollectionUtils.isEmpty(users)) {
            return 0;
        }
        return this.baseMapper.insertBatchSomeColumn(users);
    }

    public User getById(Serializable id) {
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        return this.baseMapper.selectById(id);
    }

}
